/* beautify ignore:start */
import {provide, Directive} from '@angular/core';
import {Control, NG_VALIDATORS, Validator} from '@angular/common';
/* beautify ignore:end */

@Directive({
    selector: '[email]',
    providers: [provide(NG_VALIDATORS, {useExisting: EmailValidator, multi: true})],
})

export class EmailValidator implements Validator {
    validate(c: Control): {[key: string]: any} {
        var emailRegexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (c.value && !emailRegexp.test(c.value)) {
            return {'email': true};
        }
    }
}
